<template>
  <div>
    <el-dialog
        :title="modalTile"
        :visible.sync="dialogVisible"
        :close-on-click-modal="false"
        width="500px">
      <div>
        <el-form :model="formData" label-width="0">
          <el-form-item label="">
            <el-radio-group v-model="approvalStatus">
              <el-radio label="0">{{status === '1' ? '勾选通过':'勾选驳回'}}</el-radio>
              <el-radio label="1">{{status === '1' ? '按调查对象分类通过':'按调查对象分类驳回'}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <quick-input @change="inputChange"/>
          <el-form-item label="">
            <el-input v-model="formData.remark" type="textarea" :rows="3" :placeholder="status === '1' ? '请填写通过意见':'请填写驳回意见'"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import {Component, Vue,Prop} from 'vue-property-decorator';
import {dataApproval} from "@/api/dataApproval";
import QuickInput from "@/views/quality/components/QuickInput.vue";

@Component({
  components: {QuickInput}
})
export default class DataApprovalModal extends Vue {

  @Prop() workId:any;
  modalTile = '';
  status = '';
  private ids:any = []
  private id:any = ''
  @Prop() categoryId:any
  @Prop() categoryLevel:any

  private formData:any = {
    status:'1',
    remark:''
  }
   dialogVisible = false;
   approvalStatus = '0';
   public showModal(modalTile,ids,status) {
     this.status = status
     this.modalTile = modalTile
     // this.id = id
     this.ids = ids
     this.dialogVisible = true;
   }


   submit(){
     this.$msgbox.confirm(`是否确认${this.modalTile}`,{
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async ()=>{
        const formData = Object.assign({},this.formData)
        // formData.id = this.id
        formData.workId = this.workId;
        formData.status = this.status
        if(this.approvalStatus === '0'){
          if(!this.ids.length){
            this.$message.error('请勾选数据')
            return
          }
          formData.ids = this.ids
        }else{
          formData.categoryId = this.categoryId
          formData.categoryLevel = this.categoryLevel
        }
        await dataApproval(formData)
        this.$message.success('提交成功')
        this.dialogVisible = false;
        this.$emit('success')
      }).catch(()=>{
        this.dialogVisible = false;
      })
   }
  inputChange(value){
     this.formData.remark = value
  }


}
</script>
<style lang="scss" scoped>
</style>
